package cn.huangsm.advance.ratelimiter2.controller;

import cn.huangsm.advance.ratelimiter2.AccessRateLimiter;
import cn.huangsm.advance.ratelimiter2.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试第二种rateLimiter注解方式
 *
 * @author huang
 * @PACKAGE_NAME cn.huangsm.advance.ratelimiter2
 * @PROJECT_NAME advance-code
 * @date 2019/1/19
 */
@RestController
@Slf4j
public class RateLimiterController {
    /**
     * @return
     * @AccessFast(qps = 10),在注解中配置qps参数,
     * 每秒最多10次request请求.即可实现限流效果
     */
    @GetMapping("/info")
    @AccessRateLimiter(limitNum = 2.0)
    public String info() {
        log.info("調用了方法Info");
        return "hello";
    }

    @GetMapping("/info1")
    public Result getResults() {
        log.info("调用了方法getResults");
        return Result.OK("调用了方法", null);
    }

    @AccessRateLimiter(limitNum = 100.0)
    @GetMapping("/info2")
    public Result getResultTwo() {
        log.info("调用了方法getResultTwo");
        return Result.OK("调用了方法getResultTwo", null);
    }
}
